﻿using System;
using System.Linq;
using System.Collections.Generic;
using ForumsBrowser.BusinessObjects;
using ForumsBrowser.ServiceContracts;

namespace ForumsBrowser.ObjectGateway
{
    internal static class AvailableForumsGetAction
    {
        internal static List<ForumCategory> Execute(bool refresh)
        {
            var data = ServiceFactory.Service.GetAvailableForums(refresh);

            if (data != null)
            {
                return (from item in data.Categories
                        select new ForumCategory
                        {
                            CategoryName = item.CategoryName,
                            Forums = (from i in item.AvailableForums
                                      select new Forum
                                      {
                                          LongName = i.ForumLongName,
                                          ShortName = i.ForumShortName,
                                          IsSelected = i.IsSelected
                                      }).ToList()
                        }).ToList();
            }

            return new List<ForumCategory>();
        }
    }
}
